#!/usr/bin/python
# -*- coding: UTF-8 -*-
import matplotlib
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd 

df = pd.read_csv('total.csv')
#设置X轴，这里表示是时间轴
#x0 = ['1.11','1.12','1.13','1.14','1.15','1.16','1.17','1.18','1.19','1.20','1.21','1.22','1.23','1.24','1.25','1.26','1.27','1.28','1.29']
x0 = df.columns
#设置Y轴，这是表示数据，两个方向分别表示确诊和疑似人数
#y1 = np.array([41,41,41,41,41,41,41,45,62,198,291,440,571,830,1287,1975,2744,4515,5997])
#y2 = np.array([0,0,0,0,0,0,0,0,0,0,54,37,393,1072,1965,2684,5794,6973,9239])
y1 = np.array(df.ix[0])
y2 = np.array(df.ix[1])

#设置Y轴范围
plt.ylim(-10500,6500) 

#画数据
plt.bar(x0,y1,0.9,label='确诊人数',color='r')
plt.bar(x0,-y2,0.9,label='疑似人数',color='b') 

#在柱的上方和下方另写上人数
for x,y in zip(x0,y1):
    plt.text(x,y+0.05,'%d'%y,ha='center',va='bottom')

for x,y in zip(x0,y2):
    plt.text(x,-y-500,'%d'%y,ha='center',va='bottom')

#设置X轴刻度
plt.xticks(x0) 

#设置轴标签
plt.xlabel('日期(2020年)')
plt.ylabel('人数') 

#设置显示风格
plt.grid(True)

 #设置显示图例
plt.legend()

#设置显示中文，这里用的微软雅黑字体
matplotlib.rcParams['font.sans-serif'] = ['Microsoft YaHei']
matplotlib.rcParams['font.family']='sans-serif' 

#设置标题
plt.title('新型冠状肺炎全国确诊及疑似感染人数近十九天增长趋势    2020.1.29',fontsize=18)

#显示图表
plt.show()